package com.tensquare.qa.service;

import com.tensquare.qa.dao.ProblemDao;
import com.tensquare.qa.pojo.Problem;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class ProblemService {
    @Autowired
    private ProblemDao problemDao;
    //查询最新问答列表
    public PageResult<Problem> newlist(String labelId, int page, int size) {
        Page<Problem> problemPage = problemDao.newlist(labelId, PageRequest.of(page, size));
        return new PageResult<>(problemPage.getTotalElements(),problemPage.getContent());
    }
    //查询热门问答列表
    public PageResult<Problem> hotlist(String labelId, int page, int size) {
        Page<Problem> problemPage=problemDao.hotlist(labelId,PageRequest.of(page,size));
        return new PageResult<>(problemPage.getTotalElements(),problemPage.getContent());
    }
}
